package com.newtouch.bxzs.business.train.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.train.model.bo.CourseBO;
import com.newtouch.bxzs.business.train.model.vo.CourseDetailVO;
import com.newtouch.bxzs.business.train.model.vo.CourseVO;
import com.newtouch.bxzs.business.train.service.CourseService;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程管理controller类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/2/23 11:06</td>
 * <td>dingqianbin</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author dingqianbin
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "课程管理")
@RestController
@RequestMapping(value = "/courseController")
@SuppressWarnings("unchecked")
public class CourseController {
    private static final Log logger = LogFactory.getLog(CourseController.class);

    @Autowired
    CourseService courseService;

    @ApiOperation(value = "查询课程列表信息")
    @PostMapping("/getCourseList")
    @MyLog(systemFunctionName = "课程管理", systemFunctionUrl = "/courseController/getCourseList", userOperationType = 4, userOperationSummary = "查询课程列表信息")
    BaseResponse<IPage<CourseBO>> getCourseList(@RequestBody CourseVO courseVO) {
        logger.info("查询课程列表信息");
        return RespGenerator.returnOK(courseService.getCourseList(courseVO));
    }

    @ApiOperation(value = "查看课程详细信息")
    @GetMapping("/getCourseDetail")
    @MyLog(systemFunctionName = "课程管理", systemFunctionUrl = "/courseController/getCourseDetail", userOperationType = 4, userOperationSummary = "查看课程详细信息")
    BaseResponse<CourseBO> getCourseDetail(@RequestParam(value = "courseId")  @ApiParam(value = "课程ID") String courseId) {
        logger.info("查看课程详细信息");
        return RespGenerator.returnOK(courseService.getCourseDetail(courseId));
    }

    @ApiOperation(value = "增加/修改课程信息")
    @PostMapping("/modifyCourse")
    @MyLog(systemFunctionName = "课程管理", systemFunctionUrl = "/courseController/modifyCourse", userOperationType = 5, userOperationSummary = "增加/修改课程信息")
    public BaseResponse<String> modifyCourse(@RequestBody CourseDetailVO courseDetailVO) {
        logger.info("增加/修改课程信息");
        return RespGenerator.returnOK(courseService.modifyCourse(courseDetailVO));
    }

    @ApiOperation(value = "发布/撤销课程")
    @GetMapping("/changeCourse")
    @MyLog(systemFunctionName = "课程管理", systemFunctionUrl = "/courseController/changeCourse", userOperationType = 2, userOperationSummary = "发布/撤销课程")
    public BaseResponse<Integer> changeCourse(@RequestParam(value = "courseId") @ApiParam(value = "课程ID") String courseId, @RequestParam(value = "publishStatus") @ApiParam(value = "发布状态：1-未发布；2-已发布；5-已撤销；") String publishStatus) {
        logger.info("发布/撤销课程");
        return RespGenerator.returnOK(courseService.changeCourse(courseId, publishStatus));
    }

    @ApiOperation(value = "删除/批量删除课程")
    @PostMapping("/deleteCourse")
    @MyLog(systemFunctionName = "课程管理", systemFunctionUrl = "/courseController/deleteCourse", userOperationType = 3, userOperationSummary = "删除/批量删除课程")
    public BaseResponse<Integer> deleteCourse(@RequestBody List<CourseDetailVO> courseDetailVOList) {
        logger.info("删除/批量删除课程");
        return RespGenerator.returnOK(courseService.deleteCourse(courseDetailVOList));
    }
}
